import Vue from 'vue'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 引入外部less
import './assets/less/index.less'

import store from'../store'
// 引入axios
import http from 'axios'
//引入mock
import '../api/mock.js'

import App from './App.vue'
Vue.use(ElementUI);

import VueRouter from 'vue-router'
import router from '../router'

Vue.config.productionTip = false
Vue.use(VueRouter)
// 引入axios
Vue.prototype.$http = http


router.beforeEach((to,from,next)=>{
  store.commit('getToken')
  const token =store.state.user.token
  if(!token && to.name !=='login'){
    next({name:'login'})
  }else{
    next()
  }
} )





new Vue({
  store,
  router,
  render: h => h(App),
  created(){
    store.commit('addMenu',router)
  }
  
}).$mount('#app')
